package cn.itcast.order.web;

import cn.itcast.order.pojo.Order;
import cn.itcast.order.service.OrderService;
import com.ltcast.feign.client.UserClient;
import com.ltcast.feign.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("order")
public class OrderController {

   @Autowired
   private UserClient userClint;

   @Autowired
   private OrderService orderService;

    @GetMapping("{orderId}")
    public Order queryOrderByUserId(@PathVariable("orderId") Long orderId) {
        // 根据id查询订单并返回
        Order order = orderService.queryOrderById(orderId);
        Long userId = order.getUserId();
        User user = userClint.getUser(userId);
        order.setUser(user);

        return order;
    }


    @GetMapping("getHead")
    public String getHeader(@RequestHeader(value = "truth",required = false) String truth) {
        return truth;
    }
}
